import {defHttp} from '/@/utils/http/axios';
import {useMessage} from '/@/hooks/web/useMessage';
import {VerifyMessageReq} from './model/msgPushModel';

const { createErrorModal } = useMessage();
enum Api {
  //获取短信验证码的接口
  sendUserVerifyMessage = '/msg-push-service/authUserCaptchaMsg/send',
  sendVerifyMessage = '/msg-push-service/captchaMsg/send',
}

/**
 * 需要登录
 * @description: 获取短信验证码
 */
export function sendUserVerifyMessage(params: VerifyMessageReq) {
  return new Promise((resolve, reject) => {
    defHttp.post({ url: Api.sendUserVerifyMessage, params }, { isTransformResponse: false }).then((res) => {
      console.log(res);
      if (res.success) {
        resolve(true);
      } else {
        createErrorModal({ title: '错误提示', content: res.message || '未知问题' });
        reject();
      }
    });
  });
}

/**
 * 无需登录
 * @param params 
 * @returns 
 */
export function sendVerifyMessage(params: VerifyMessageReq) {
  return new Promise((resolve, reject) => {
    defHttp.post({ url: Api.sendVerifyMessage, params }, { isTransformResponse: false }).then((res) => {
      console.log(res);
      if (res.success) {
        resolve(true);
      } else {
        createErrorModal({ title: '错误提示', content: res.message || '未知问题' });
        reject();
      }
    });
  });
}

